﻿using System;
using System.Reflection;
using NExt.Handler.Base.Common.Cache;

namespace NExt.Handler.Base.Common.Manager
{
    public class TypeManager : ConcurrentCache<TypeManager, string, Type>
    {
        public static Type GetType(string fileName, string typeName)
        {
            string key = string.Format("{0}.{1}", typeName, fileName);
            Type type = GetOrAdd(key, () =>
                                          {
                                              Assembly assembly = AssemblyManager.GetAssembly(fileName);
                                              return assembly.GetType(typeName);
                                          });

            return type;
        }

        public static string GetDefaultConfigJsName(Type type)
        {
            string fullName = type.FullName;
            string defaultConfigJsName = string.Format("{0}.DefaultConfig", fullName);
            return defaultConfigJsName;
        }
    }
}
